package com.sen.day11;

import java.util.Arrays;
import java.util.Scanner;

public class MazeOver {
	static Scanner scanner = new Scanner(System.in);

	public void input() {
		// 迷宫的行 列
		 System.out.println("请输入范围大小回车继续输入连通点回车确认（连通点格式：0,1 0,2;）");
		 String rowAndClomun = scanner.nextLine();
//		String rowAndClomun = "3 3";
		// 连通位置
		 String location = scanner.nextLine();
//		String location ="0,1 0,2;0,0 1,0;0,1 1,1;0,2 1,2;1,0 1,1;1,1 1,2;1,1 2,1;1,2 2,2;2,0 2,1";
		// 字符串转换为int型
		int mazeRow = 0;
		int mazeClomun = 0;
		String[] rowandClomun = rowAndClomun.split(" ");
		try {
			if (Integer.parseInt(rowandClomun[0]) > 1 && Integer.parseInt(rowandClomun[1]) > 1) {
				mazeRow = Integer.parseInt(rowandClomun[0]);
				mazeClomun = Integer.parseInt(rowandClomun[1]);
			} else {
				System.out.println("输入的迷宫行数列数错误");
			}
		} catch (ArrayIndexOutOfBoundsException e1 ) {
			// TODO 自动生成的 catch 块
			System.out.println("Incorrect command format​.");
			System.exit(0);
		}catch (NumberFormatException e1) {
			System.out.println("Incorrect command format​.");
			System.exit(0);
			// TODO: handle exception
		}
		String[][] maze = new String[mazeRow * 2 + 1][mazeClomun * 2 + 1];
		String[] mazePoint = location.split(",| |;");
		try {
			for (int i = 0; i < mazePoint.length; i += 2) {
				if (Integer.parseInt(mazePoint[i]) < 0 || Integer.parseInt(mazePoint[i]) > mazeRow
						|| Integer.parseInt(mazePoint[i + 1]) < 0 || Integer.parseInt(mazePoint[i + 1]) > mazeClomun) {
					System.out.println("Number out of range");
					System.exit(0);
				}
			}
		}
	catch (NumberFormatException e) {
			// TODO 自动生成的 catch 块
			System.out.println("Invalid number format");
			System.exit(0);
		}
		boolean flag = false;
		//遍历迷宫，
		try {
			for (int i = 0; i < maze.length; i++) {
				for (int j = 0; j < maze[i].length; j++) {
					//设置标志位，判断是w还是r
					flag = false;
					for (int k = 0; k < mazePoint.length; k += 4) {
					//判断输入的通道是否连通
						try {
							if (((Integer.parseInt(mazePoint[k]) == Integer.parseInt(mazePoint[k + 2])
									&& ((Integer.parseInt(mazePoint[k + 1]) - Integer.parseInt(mazePoint[k + 3]) == -1)
											|| Integer.parseInt(mazePoint[k + 1])
													- Integer.parseInt(mazePoint[k + 3]) == 1)))
									|| ((Integer.parseInt(mazePoint[k + 1]) == Integer.parseInt(mazePoint[k + 3])
											&& ((Integer.parseInt(mazePoint[k]) - Integer.parseInt(mazePoint[k + 2]) == 1)
													|| (Integer.parseInt(mazePoint[k])
															- Integer.parseInt(mazePoint[k + 2]) == -1))))) {
								//判断连通点是否可以导通
								if ((Integer.parseInt(mazePoint[k]) + Integer.parseInt(mazePoint[k + 2]) + 1 == i
										&& Integer.parseInt(mazePoint[k + 1]) + Integer.parseInt(mazePoint[k + 3]) + 1 == j)
										|| (i % 2 != 0 && j % 2 != 0)) {
									//设置标志位为true
									flag = true;
								}
							} else {
								System.out.println("Maze format error.");
								System.exit(0);
							}
						} catch (Exception e) {
							// TODO 自动生成的 catch 块
							System.out.println("Invalid number format");
							System.exit(0);
						}
					}
					//给迷宫数组渲染为W或者R通过标志位判断
					if (flag) {
						
						maze[i][j] = "[R]";

					} else {
						maze[i][j] = "[W]";
					}
					System.out.print(maze[i][j]);
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			// TODO 自动生成的 catch 块
			System.out.println("Invalid number format");
			System.exit(0);
		}
	}

	public static void main(String[] args) {
		MazeOver input = new MazeOver();
		input.input();
	}
}